<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>角色新增</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}"/>
</head>
<body>
<form class="layui-form" th:action="@{/role/add}" method="post" style="margin-top: 15px">
    <div class="layui-form-item">
        <label class="layui-form-label">编码</label>
        <div class="layui-input-inline">
            <input type="text" name="roleCode" lay-verify="required" placeholder="请输入编码" autocomplete="off" class="layui-input"/>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
            <input type="text" name="roleName" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input"/>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文本域</label>
        <div class="layui-input-inline">
            <textarea name="memo" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="lay-submit" lay-filter="formRole">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script th:src="@{/static/layui/layui.all.js}"></script>
<script type="text/javascript" th:inline="javascript">

    var ctxPath = /*[[@{/}]]*/ '';

    layui.use('form', function(){
        var form = layui.form;
        var index = parent.layer.getFrameIndex(window.name);

        //监听提交
        form.on('submit(formRole)', function(data){
            layui.$.post({
                url: ctxPath + '/role/add',
                data:data.field,
                success:function (res) {
                    if(res.status){

                        parent.layer.close(index);

                    }else {
                        layer.msg(JSON.stringify(data.message));
                    }
                }
            });
            return false;
        });

    });
</script>
</html>